package com.angel.architecture.persistence.ids.impl;

import org.safehaus.uuid.UUID;

import com.angel.architecture.persistence.ids.ObjectId;
import com.angel.common.interfaces.Identificable;

/**
 * TODO Write comments.
 * Representacion de un id unico de objetos
 */
public class ObjectIdImpl implements ObjectId {

    private static final long serialVersionUID = -8061896516485596421L;

    private UUID uuid;

    public ObjectIdImpl(UUID uuid) {
        this.uuid = uuid;
    }


    public String toString() {
        return uuid.toString();
    }


    public int compareTo(Object otherObject) {
        ObjectIdImpl otherObjectId = ( ObjectIdImpl ) otherObject;

        return this.uuid.compareTo(otherObjectId.uuid);
    }


    public boolean equals(Object _otherObject) {
        if ( this == _otherObject ) {
            return true;
        }
        if ( !(_otherObject instanceof Identificable) ) {
            return false;
        }

        ObjectIdImpl _otherObjectId = ( ObjectIdImpl ) (( Identificable ) _otherObject).getId();

        if ( uuid != null ? !uuid.equals(_otherObjectId.uuid) : _otherObjectId.uuid != null ) {
            return false;
        }

        return true;
    }


    public int hashCode() {
        return (uuid != null ? uuid.hashCode() : 0);
    }


    public ObjectId getId() {
        return this;
    }

    /**
     *
     * @see ObjectId#getAsString()
     */
    public String getIdAsString(){
    	return this.toString();
    }

    public ObjectIdImpl() {
    }

    public void setUuid(String uuid) {
        this.uuid = new UUID(uuid);
    }

    public String getUuid() {
        return this.toString();
    }
}
